#!/usr/bin/env tclsh

source bin/xsmack-lib.tcl

if { [ llength $argv ] < 2 } {
    puts "usage: targets.tcl <user> <exercise>"
    exit 1
}

set usr [ lindex $argv 0 ]
set exercise [ lindex $argv 1 ]

set plans users/${usr}/plans

set planfiles [ glob $plans/plan*.txt ]

set e [ join [ list {\[} $exercise {\]} .* ] "" ]
set t {target=([[:digit:].]*)}
set pattern $e$t
show pattern
# exit 0

foreach planfile $planfiles {
    set fd [ open $planfile "r" ]

    while { [ gets $fd line ] >= 0 } {
	if { [ regexp $pattern $line x target  ] } {
	    regexp "plan-(.*).txt" $planfile x date
	    puts "$date $target"
	    break
	}
    }

    close $fd
}

# let
